package algotithm.weekendrace.leetcode231.test2;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/7-10:29
 * @Title 5698. 构成特定和需要添加的最少元素
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1,-1,1};
        int limit = 3;
        int goal = -4;
        int minElements = solution.minElements(nums, limit, goal);
        System.out.println(minElements);
    }


    public int minElements(int[] nums, int limit, int goal) {
        long ans = 0;
        long res = 0;
        for (int i = 0; i < nums.length; i++) {
            ans += nums[i];
        }
        long diff = Math.abs(goal - ans);
        if (diff % limit != 0) {
            res = 1;
        }
        res += diff / limit;
        return (int)res;
    }
}
